﻿using HelloMinasan.Web.Song.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HelloMinasan.Business;
using HelloMinasan.Web.Song.ViewModels;
using HelloMinasan.Framework.Web;
using HelloMinasan.Business.Extend;

namespace HelloMinasan.Web.Song.Controllers
{

    public class HomeController : ApplicationController
    {
        //private HomeRepository _repository = new HomeRepository();
        //public HomeController()
        //    : this(new HomeRepository())
        //{
        //}
        //public HomeController(HomeRepository repository)
        //{
        //    // TODO: Complete member initialization
        //    this._repository = repository;
        //}

        private ISongService songService;

        public HomeController(ISongService songService)
        {
            this.songService = songService;
        }

        //[AllowAnonymous]
        public ActionResult Index()
        {
            var model = new HomeModels
            {
                TopHighestScoreSongs = songService.GetTopHighestSongs(),
                TopHighestScoreUsers = songService.GetTopHighestUsers(),
                TopNewestQAs = songService.GetTopNewestQAs(),
                TotalSong = songService.TotalSongCount(),
                TotalThread = songService.TotalThreadCount(),
                TotalUser = songService.TotalThreadCount()

            };
            return View(model);
        }
        //[AllowAnonymous]
        public ActionResult Search(string id)
        {
            if (String.IsNullOrEmpty(id)) id = "";
            var model = songService.GetSearchSongs(id);
            ViewBag.Keyword = id;
            return View(model);
        }
        //[AllowAnonymous]
        public ActionResult Error()
        {
            return View();
        }
    }
}
